package study.sharding.shardingjdbc.support.encrypt;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.encrypt.strategy.spi.Encryptor;

import java.util.Objects;
import java.util.Properties;

@Slf4j
public class CustomEncryptor implements Encryptor {

    @Getter
    @Setter
    private Properties properties;

    @Override
    public void init() {
    }

    @Override
    public String getType() {
        return "hid";
    }

    @Override
    public String encrypt(Object plaintext) {
        log.info(">>>>>>>>>> encrypt {}", plaintext);
        if (Objects.isNull(plaintext)) {
            return null;
        }
        return plaintext.toString();
    }

    @Override
    public Object decrypt(String ciphertext) {
        log.info(">>>>>>>>>> decrypt {}", ciphertext);
        return StrUtil.hide(ciphertext, 3, 5);
    }
}
